﻿using System;
 
namespace DBETLTools
{
    class Program
    {
        static void Main(string[] args)
        {
            DBConfig loadConfig = DBConfig.Config;
            //loadConfig.DBSource = "Database=eyeofwisdom;Data Source=127.0.0.1;Port=3306;User Id=root;Password=Az821abc;Charset=utf8;TreatTinyAsBoolean=false;";

            //DemoMysql demo = new DemoMysql(loadConfig.DBSource,loadConfig.DBSource);
            //loadConfig.DBTables = new System.Collections.Generic.List<DBTable>();
            //foreach (string item in demo.GetTABLES("eyeofwisdom"))
            //{
            //    loadConfig.DBTables.Add(new DBTable() { SourceName = item, TargetName = item,  dBTRIGGERs=new DBTRIGGER[3] });

            //}
            //DBConfig.SConfig(loadConfig);

            //Console.WriteLine(demo.Ist("sys_config", DBTRIGGER.INSERT)); 
            ConsoleKeyInfo a1;
            int runcode = 1;

            if (args.Length>0)
            {
                if(args[0]=="2")
                {
                    Console.WriteLine("正在执行数据同步......");
                    run2();
                   
                }
            }
 
            while (true)
            {
                Console.Clear();

                Console.WriteLine("数据在线同步工具 v0.02");
                Console.WriteLine("1   初始化源数据库 添加同步触发器");
                Console.WriteLine("2   执行数据同步");
                Console.WriteLine("                         当前版本:20240402");
                a1 = Console.ReadKey(false);
                if (a1.KeyChar == '1')
                {

                    run1();
                    Console.WriteLine("创建数据表和触发器成功");

                }
                if (a1.KeyChar == '2' )
                {
                    Console.WriteLine("正在执行数据同步");
                    run2();
                }
                if(runcode==2)
                {
                    Console.WriteLine("正在执行数据同步");
                    run2();

                }
                if (a1.KeyChar == 'q')
                {
                    Console.WriteLine("退出成功");
                    break;

                }

                


            }
           
           


            
        }
        private static void run1()
        {
            DBConfig config = DBConfig.Config;

            DemoMysql demo = new DemoMysql(config.DBSource,config.DBTarget);
            demo.Install(config);
        }
        private static void run2()
        {
            DBConfig config = DBConfig.Config;

            DemoMysql demo = new DemoMysql(config.DBSource, config.DBTarget);
            demo.RunCpoy(2000);
        }
    }
}
